package com.wlhse.controller;

import com.wlhse.entity.CheckTypePojo;
import com.wlhse.service.CheckTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("CheckTypeController")
@RequestMapping("/api/v3")
//检查类型配置
public class CheckTypeController {

    @Resource
    private CheckTypeService checkTypeService;


    //根据id查询单条记录
    @RequestMapping(value = "/checkType/{id}", method = RequestMethod.GET, produces = {"application/json;charset=utf-8"})
    public String queryById(@PathVariable(value = "id") Integer id) {
        return checkTypeService.queryById(id);
    }

    //根据name模糊查询或查询所有
    @RequestMapping(value = "/checkType", method = RequestMethod.GET, produces = {"application/json;charset=utf-8"})
    public String queryByName(@ModelAttribute CheckTypePojo checkTypePojo) {
        return checkTypeService.query(checkTypePojo.getCheckTypeName(), checkTypePojo.getPageIdx(),
                checkTypePojo.getPageSize(), checkTypePojo.getType());
    }

    //增
    @RequestMapping(value = "/checkType", method = RequestMethod.POST, produces = {"application/json;charset=utf-8"})
    public String add(@RequestBody(required = false) CheckTypePojo checkTypePojo) {
        return checkTypeService.addCheckType(checkTypePojo);
    }

    //删
    @RequestMapping(value = "/checkType/{id}", method = RequestMethod.DELETE, produces = {"application/json;charset=utf-8"})
    public String delete(@PathVariable int id) {
        return checkTypeService.deleteCheckType(id);
    }

    //改
    @RequestMapping(value = "/checkType/{id}", method = RequestMethod.PUT, produces = {"application/json;charset=utf-8"})
    public String update(@RequestBody(required = false) CheckTypePojo checkTypePojo, @PathVariable int id) {
        checkTypePojo.setId(id);
        return checkTypeService.updateCheckType(checkTypePojo);
    }
}
